/* Sorts an point array of integers using Quicksort algorithm */
#include <stdio.h>
#define N 10
int *split_point(int *low, int *high);
void quicksort_point(int *low, int *high);
int main(void)
{
    int a[N], i;
    int *p = a;
    printf("Enter %d numbers to be sorted: ", N);
    for (i = 0; i < N; i++)
        scanf("%d", &a[i]);
    quicksort_point(a, &a[N - 1]);
    printf("In sorted order: ");
    for (; p < a + N; p++)
        printf("%d ", *p);
    printf("\n");
    return 0;
}
void quicksort_point(int *low, int *high)
{
    int *middle;
    if (low >= high) return;
    middle = split_point(low, high);
    quicksort_point(low, middle - 1);
    quicksort_point(middle + 1, high);
}

int *split_point(int *low, int *high)
{
    // 基准点不能是指针，之前用指针导致报错了
    int part_element = *low;
    for (;;) {
        while (low < high && part_element <= *high)
            high--;
        if (low >= high) break;
        *low++ = *high;
        while (low < high && *low <= part_element)
            low++;
        if (low >= high) break;
        *high-- = *low;
    }
    *high = part_element;
    return high;
}